use std::env;

use sqlx::{mysql::MySqlPoolOptions, MySqlPool};

pub async fn get_db_pool() -> MySqlPool {
    let database_url = env::var("DATABASE_URL").expect("Not configured in .env");

    let pool_connect = MySqlPoolOptions::new()
        .max_connections(5)
        .connect(&database_url)
        .await;
    match pool_connect {
        Ok(conn) => conn,
        Err(err) => {
            println!("err message: {:?}", err);
            panic!("数据库连接异常");
        }
    }
}
